<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
</head>
<body>
<input type="text" id="i1" placeholder="姓名">
<input type="text" id="i2" placeholder="工资">
<input type="text" id="i3" placeholder="岗位">
<hr>
<button onclick="addEmp()">添加</button>
<table>
    <caption>员工表</caption>
    <tr>
        <th>姓名</th>
        <th>年龄</th>
        <th>职位</th>
    </tr>


</table>

<script>
    function addEmp()
    {
        let arr = [];
        // 1 获取值
        let name = document.getElementById('i1').value.trim();
        let age = document.getElementById('i2').value.trim();
        let job = document.getElementById('i3').value.trim();

        if (!name || !age || !job)
        {
            alert("请输入完整的信息")
            return
        }


        // 2 创建行
        let trE = document.createElement("tr");
        let nameTd = document.createElement("td");
        let ageTd = document.createElement("td");
        let jobTd = document.createElement("td");

        // td添加值
        nameTd.innerHTML = name;
        ageTd.innerHTML = age;
        jobTd.innerHTML = job;

        // 把tr里的东西加到tr中
        trE.append(nameTd,ageTd,jobTd);
        // 找到table 把 tr加到上边
        let tableE = document.querySelector("table");
        tableE.append(trE);

        document.getElementById("i1").value = '';
        document.getElementById("i2").value = '';
        document.getElementById("i3").value = '';

        arr.push({
            name:name,
            age:age,
            job:job
        });
        console.log(arr[arr.length-1])

    }
</script>


</body>
</html>